<!doctype html>
<html lang="en">

<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Hello, world!</title>
    <!-- 成品出货 -->
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="../css/font-awesome.min.css">
    <link rel="stylesheet" href="../fonts/iconfont.css">
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <link rel="stylesheet" href="../css/bootstrap-select.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <style>
          .bd-placeholder-img {
            font-size: 1.125rem;
            text-anchor: middle;
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none;
        }

        @media (min-width: 768px) {
            .bd-placeholder-img-lg {
                font-size: 3.5rem;
            }
        }

        html,
        body {
            height: 100%;
        }

        body {
            padding-bottom: 40px;
            background-color: #fff;
        }

        .form-signin {
            width: 100%;
            max-width: 640px;
            margin: auto;
            padding: 15px;
        }

        .form-signin .checkbox {
            font-weight: 400;
        }
      
        .form-signin .form-control {
            position: relative;
            box-sizing: border-box;
            height: auto;
            padding: 10px;
            font-size: 16px;
        }
       
        .form-signin .form-control:focus {
            z-index: 2;
        }

        .form-signin input[type="email"] {
            margin-bottom: -1px;
            border-bottom-right-radius: 0;
            border-bottom-left-radius: 0;
        }

        .form-signin input[type="password"] {
            margin-bottom: 10px;
            border-top-left-radius: 0;
            border-top-right-radius: 0;
        }

        .sr-only2 {
            margin-top: 15px;
        }


        .logodiv img {
            width: 240px;
            margin: 0 auto;
            display: block;
        }
        .nav-tabs {
            position: sticky;
            top: 0;
            padding-top: 10px;
            z-index: 999;
            background-color: #fff;
        }
        
        .tab-content {
            padding: 0 10px;
            overflow-x: hidden;
            overflow-y: scroll;

        }

        .logodiv {
            text-align: center;
        }

        .logodiv h1 {
            font-size: 1.4rem;
            color: #03357a;
            margin-top: 20px;
            margin-bottom: 20px;
        }

        .logodiv h2 {
            font-size: 1.5rem;
            margin-bottom: 80px;
        }

        .fgtpaws {
            text-align: center;
            margin-top: 10px;
        }

        .btn {
            padding: 0.375rem 0.15rem
        }

        .btn-tiqu {
            width: 125px;
            margin: 0 auto;
            display: block;
        }

        .buytitle {
            font-size: 1rem;
            color: #03357a;
            margin-top: 20px;
        }

        .buytitle span {
            font-size: 1rem;
            color: #999;
        }
        .action-row button {
            margin-bottom: 15px;
        }

        .buysearch {
            font-size: smaller;
        }

        .formscreen .form-control-theme {
            font-size: smaller;
        }

        .action-row {
            position: fixed;
            width: 100%;
            bottom: 0;
            margin-top: 0;
            margin-bottom: 0;
            background: #fff;
            left: 0;
        }

        .bootstrap-select {
            width: calc(100% - 0px) !important;
            position: relative;
        }
        .bootstrap-select option{
            position: absolute;
            top: 100%;
            left: 0;
        }
        .formscreen .filter-option-inner-inner {
            font-size: smaller;
        }

        .myselect {
            width: calc(100% - 0px);
        }
        .btn-action:disabled {
            background: #D9D9DA !important;
            color: #808081 !important;
        }
        .wareContent{
            display: flex;
            justify-content: center;
            align-items: center;
            position: relative;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="container2">
            <div class="modal fade fullmodal show" style="display: block;" id="exampleModal"
                tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-body">
                            <div class="logodiv">
                                <img class="bannerlogo pt-3" src="../image/logo.jpeg">
                                <h3 class="mt-3 mb-5">{{lan['Customer_Shipment']}}</h3>
                            </div>
                            <div class="row  align-items-center">



                                <div class="col-12 col-sm-6 col-md-3">
                                    <div class="d-flex bd-highlight align-items-center">
                                        <div class="p-2 bd-highligh  flex-shrink-0 filedlabel">{{lan['RCV_Date']}}</div>
                                        <div class="p-2 flex-grow-1 bd-highlight">
                                            <input type="date" v-model="searchdata.ArrivedDate"
                                                :placeholder="lan['Date_placeholder']"
                                                class="form-control form-control-theme" value="">
                                        </div>
                                    </div>
                                </div>
                                <div class="col-12 col-sm-6 col-md-3">
                                    <div class="d-flex bd-highlight align-items-center">
                                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['RMA_Num']}}</div>
                                        <div class="p-2 flex-grow-1 bd-highlight">
                                            <input type="text" id="RMANum" v-model="searchdata.RMANum"
                                                @blur="searData()"
                                                :placeholder="lan['palase_enter'] + lan['RMA_Num']"
                                                class="form-control form-control-theme" value="">
                                        </div>
                                    </div>
                                </div>

                                <div class="col-12 col-sm-6 col-md-3">
                                    <div class="d-flex bd-highlight align-items-center">
                                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['CustID']}}</div>
                                        <div class="p-2 flex-grow-1 bd-highlight">
                                            <input type="text" id="orderNum" v-model="searchdata.custID"
                                                :placeholder="lan['CustID_placeholder']"
                                                class="form-control form-control-theme" value="">
                                        </div>
                                    </div>
                                </div>


                                <div class="col-12">
                                    <div class="d-flex bd-highlight align-items-center">
                                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['User']}}</div>
                                        <div class="p-2 flex-grow-1 bd-highlight">
                                            <input type="text" v-model="searchdata.name" disabled
                                                class="form-control form-control-theme" value="">
                                        </div>
                                    </div>
                                </div>


                            </div>

                            <div class=" row justify-content-center mt-4">
                                <div class="col-4 col-md-4">
                                    <button type="button" onclick="loadData()" tapmode=""
                                        class="btn btn-primary btn-action">{{lan['OK']}}</button>
                                </div>


                                <div class="col-4 col-md-4">
                                    <button type="button" tapmode="" onclick="close_win()"
                                        class="btn btn-primary btn-action">{{lan['Cancel']}}</button>
                                </div>

                            </div>

                        </div>

                        <div class="modal-footer">
                            <div class="copyright">
                                <div class="row" :gutter="10">
                                    <div  class="col-5" style="text-align: right;">{{lan['Version']}}：</div>
                                    <div  class="col-7">{{appversion}}</div>
                                    <div  class="col-5"  style="text-align: right;">{{lan['Site']}}：</div>
                                    <div  class="col-7">{{SiteName}}</div>
                                    <div  class="col-5"  style="text-align: right;">{{lan['Company']}}：</div>
                                    <div  class="col-7">{{CompanyName}}</div>
                                </div>
                            </div>
                        </div>

                    </div>
                </div>
            </div>

            <ul class="nav nav-tabs" id="myTab" role="tablist">
                <li class="nav-item" role="presentation">
                    <a class="nav-link active " id="home-tab" data-toggle="tab" href="#home" role="tab"
                        aria-controls="home" aria-selected="true">RMA List</a>
                </li>
                <li class="nav-item" role="presentation">
                    <a class="nav-link" id="profile-tab" data-toggle="tab" href="#profile" role="tab"
                        aria-controls="profile" aria-selected="false">Receipts</a>
                </li>

            </ul>
            <div class="tab-content" id="myTabContent">
                <div class="tab-pane  show active" id="home" role="tabpanel" aria-labelledby="home-tab">
                    <h2 class="buytitle"><span>({{lan['Pls_select']}})</span></h2>
                    <button type="button" @click="list1_selectall()"
                    class="btn btn-link">{{lan['Select_All']}}</button>
                    <div  class="row align-items-center">
                        <div v-for="(item,k) in list" :key="'shou'+k" v-if="item.shoucai == 1" id="shouitem"
                            class="col-12">
                            <div class="d-flex bd-highlight align-items-start">
                                <div class="pt-2 bd-highligh">
                                    <div class="custom-control custom-switch">
                                        <!-- 请选择 -->
                                        <input :disabled="Lot_btn"  type="checkbox" v-model='item.itemChecked' @change="toshou(item,k)" class="custom-control-input"
                                            :id="'Switch'+item.RMADtl_RMANum+'-'+item.RMADtl_RMALine+'-'+item.RMADtl_OrderNum +'-'+item.RMADtl_OrderLine">
                                        <label class="custom-control-label"
                                            :for="'Switch'+item.RMADtl_RMANum+'-'+item.RMADtl_RMALine+'-'+item.RMADtl_OrderNum +'-'+item.RMADtl_OrderLine"></label>
                                    </div>
                                </div>
                                <div class="pt-2 flex-grow-1 bd-highlight">
                                    <table class="table table-buy table-borderless table-sm">
                                        <tr>
                                            <td class="ttl">{{lan['RMA_Num']}}</td>
                                            <td class="ttl">{{lan['RMA_Line']}}</td>
                                            <td class="ttl">{{lan['CustID']}}</td>
                                        </tr>
                                        <tr>
                                            <td>{{item.RMADtl_RMANum}}</td>
                                            <td>{{item.RMADtl_RMALine}}</td>
                                            <td>{{item.Customer_CustID}}</td>
                                        </tr>
                                        <tr>
                                            <td class="ttl">{{lan['Sales_Order']}}</td>
                                            <td class="ttl">{{lan['Sales_Line']}}</td>
                                            <td class="ttl">{{lan['Sales_Rel']}}</td>
                                        </tr>
                                        <tr>
                                            <td>{{item.RMADtl_OrderNum}}</td>
                                            <td>{{item.RMADtl_OrderLine}}</td>
                                            <td>{{item.RMADtl_OrderRelNum}}</td>
                                        </tr>
                                        <tr>
                                            <td class="ttl">{{lan['Part']}}</td>
                                            <td class="ttl"></td>
                                            <td class="ttl">{{lan['Qty']}}</td>
                                        </tr>
                                        <tr>
                                            <td>{{item.RMADtl_PartNum}}</td>
                                            <td></td>
                                            <td>{{item.TotalQty}}{{item.RMADtl_ReturnQtyUOM}}</td>
                                        </tr>
                                        <tr>
                                            <td class="ttl" colspan="3">{{lan['Desc']}}</td>
                                        </tr>
                                        <tr>
                                            <td colspan="3">{{item.RMADtl_LineDesc}}</td>
                                        </tr>
                                       
                                    </table>
                                </div>
                            </div>
                        </div>

                    </div>
                </div>
                <div class="tab-pane " id="profile" role="tabpanel" aria-labelledby="profile-tab">
                    <h2 class="buytitle"><span>({{lan['Cancel']}})</span></h2>
                    <button type="button" @click="list2_selectall()"
                    class="btn btn-link">{{lan['Un_Select_All']}}</button>
                    <div   class="row   align-items-center">
                        <div v-for="(item,k) in list" :key="'cai'+k" v-if="item.shoucai == 2" id="caiitem"
                            class="col-12 col-sm-6 col-md-4">
                            <div class="d-flex bd-highlight align-items-start">
                                <div class="pt-2 bd-highligh">
                                    <div class="custom-control custom-switch">
                                        <!-- 请选择 -->
                                        <input :disabled="Lot_btn" type="checkbox" @change="toshou(item,k)" class="custom-control-input"
                                            :id="'Switch'+item.RMADtl_RMANum+'-'+item.RMADtl_RMALine+'-'+item.RMADtl_OrderNum +'-'+item.RMADtl_OrderLine">
                                        <label class="custom-control-label"
                                            :for="'Switch'+item.RMADtl_RMANum+'-'+item.RMADtl_RMALine+'-'+item.RMADtl_OrderNum +'-'+item.RMADtl_OrderLine"></label>
                                    </div>
                                </div>
                                <div class="pt-2 flex-grow-1 bd-highlight">
                                    <table class="table table-buy table-borderless table-sm">
                                        <tr>
                                            <td class="ttl">{{lan['RMA_Num']}}</td>
                                            <td class="ttl">{{lan['RMA_Line']}}</td>
                                            <td class="ttl">{{lan['CustID']}}</td>
                                        </tr>
                                        <tr>
                                            <td>{{item.RMADtl_RMANum}}</td>
                                            <td>{{item.RMADtl_RMALine}}</td>
                                            <td>{{item.Customer_CustID}}</td>
                                        </tr>
                                        <tr>
                                            <td class="ttl">{{lan['Sales_Order']}}</td>
                                            <td class="ttl">{{lan['Sales_Line']}}</td>
                                            <td class="ttl">{{lan['Sales_Rel']}}</td>
                                        </tr>
                                        <tr>
                                            <td>{{item.RMADtl_OrderNum}}</td>
                                            <td>{{item.RMADtl_OrderLine}}</td>
                                            <td>{{item.RMADtl_OrderRelNum}}</td>
                                        </tr>
                                        <tr>
                                            <td class="ttl">{{lan['Part']}}</td>
                                            <td class="ttl"></td>
                                            <td class="ttl">{{lan['Qty']}}</td>
                                        </tr>
                                        <tr>
                                            <td>{{item.RMADtl_PartNum}}</td>
                                            <td></td>
                                            <td>{{item.TotalQty}}{{item.RMADtl_ReturnQtyUOM}}</td>
                                        </tr>
                                        <tr>
                                            <td class="ttl" colspan="3">{{lan['Desc']}}</td>
                                        </tr>
                                        <tr>
                                            <td colspan="3">{{item.RMADtl_LineDesc}}</td>
                                        </tr>
                                       
                                    </table>
                                    <table  class="table table-buy table-borderless table-sm">
                                        <tr>
                                            <td style="width: 33.3%;" class="ttl">{{lan['Qty']}}</td>
                                            <td style="width: 33.3%;" class="ttl">{{lan['WareHouseCode']}}</td>
                                            <td style="width: 33.3%;" class="ttl">{{lan['BinNum']}}</td>
                                        </tr>
                                        <tr>
                                            <td style="width: 33.3%;">
                                                <div class="wareContent">
                                                    <input  type="number"
                                                    :disabled="Lot_btn"
                                                    @input="checkDecimal(item,k)"
                                                    @change="checkNum(item,k)" 
                                                    :step="item.AllowDecimals ? 'any' : '1'"
                                                    v-model="item.OnhandQty"
                                                    class="form-control form-control-num" value="">
                                                    <span> {{item.IUM}}</span>
                                                </div>  
                                            </td>
                                            <td style="width: 33.3%;">
                                                <div class="wareContent">
                                                    <input   v-if="!item.warehouseFlag" type="text"
                                                    :disabled = "Lot_btn"
                                                    v-model="list[k].WareHouseCode"
                                                    @click="warehouseFocus(item,k)"
                                                    class="form-control form-control-num" value="">
                                                    <select  v-if="item.warehouseFlag"
                                                    :disabled="Lot_btn"
                                                    @change="binNumChange(item,k)" v-model="list[k].WareHouseCode" 
                                                        class="form-control"    data-live-search="true">
                                                        <option v-for="(item2,index2) in item.WareHouseCodeList" :key="index2" 
                                                            :value="item2.Warehse_WarehouseCode" :data-name="item2.Warehse_WarehouseCode">
                                                            {{item2.Warehse_WarehouseCode}}</option>
                                                    </select>
                                                    <i v-if="!item.warehouseFlag" style="margin-left: 5px;" @click="onWareQuery(item,k)" class="iconfont icon-scan"></i>
                                                    <i v-if="item.warehouseFlag" style="margin-left: 5px;" @click="onWareScan(item,k)" class="iconfont icon-query"></i>
                                                </div>
                                            </td>
                                            <td style="width: 33.3%;">
                                                <div class="wareContent">
                                                    <input   v-if="!item.binFlag" type="text"
                                                    @click="binFocus(item,k)"
                                                    :disabled = "Lot_btn"
                                                    v-model="list[k].BinNum"
                                                    class="form-control form-control-num" value="">
                                                    <select v-if="item.binFlag"  
                                                        :disabled="Lot_btn"
                                                        @change="numChange(item,k)"   v-model="list[k].BinNum" 
                                                        class="form-control" data-live-search="true">
                                                        <option v-for="(item2,index2) in item.BinNumList" :key="index2"  :value="item2.WhseBin_BinNum" >
                                                            {{item2.WhseBin_BinNum}}
                                                        </option>
                                                    </select>
                                                    <i  v-if="!item.binFlag" style="margin-left: 5px;" @click="onBinQuery(item,k)" class="iconfont  icon-scan"></i>
                                                    <i  v-if="item.binFlag" style="margin-left: 5px;" @click="onBinScan(item,k)" class="iconfont icon-query"></i>
                                                </div>
                                            </td>
                                        </tr>
                                    </table>
                                    <table  class="table table-buy table-borderless table-sm">
                                        <tr>
                                            <td colspan="4" class="ttl">{{lan['Lot']}}</td>
                                        </tr>
                                        <tr>
                                            <td colspan="3">
                                                <div class="wareContent">
                                                    <input  type="number"
                                                    v-if="item.lotFlag"
                                                    @blur="lotBlur(item,k)"
                                                    :disabled="!item.Part_TrackLots || Lot_btn"
                                                    v-model="item.LotNum"
                                                    class="form-control form-control-num" value="">
                                                    <input  type="number"
                                                    v-if="!item.lotFlag"
                                                    :disabled="!item.Part_TrackLots || Lot_btn"
                                                    @click="lotFocus(item,k)"
                                                    v-model="item.LotNum"
                                                    class="form-control form-control-num" value="">
                                                    <i  v-if="!item.lotFlag" style="margin-left: 5px;" @click="onLotQuery(item,k)" class="iconfont  icon-scan"></i>
                                                    <i  v-if="item.lotFlag" style="margin-left: 5px;" @click="onLotScan(item,k)" class="iconfont icon-query"></i>
                                                    <!-- 生成批号按钮 -->
                                                    <button style="margin-left: 3px;width: 120px;"  :disabled="item.is_Lot == 2 || Lot_btn" :id="'GetLotNum'+k"
                                                        type="button" @click="GenerateNewLotNum(k,2);"
                                                        class="btn  btn-sm" :class="(item.is_Lot == 2 || Lot_btn) ? 'btn-secondary':'btn-primary'">{{lan['Generate_lot_number']}}
                                                    </button>
                                                    <!-- 批次属性按钮 -->
                                                    <button style="margin-left: 3px; width: 100px;"  :disabled="item.BatchProperties" type="button" @click="BatchProperties(item,k);"
                                                        class="btn  btn-sm" :class=" item.BatchProperties ? 'btn-secondary':'btn-primary'">{{lan['Batch_Properties']}}
                                                    </button>
                                                </div>
                                            </td>
                                            <td>
                                                <button style="width: 80px;" type="button" tapmode="" @click="toSerial(item,k)" :disabled="!item.Part_TrackSerialNum"
                                                :class=" item.Part_TrackSerialNum == false ? 'btn-secondary':'btn-primary'"
                                                class="btn btn-primary  btn-block">{{lan['Serial_No']}} <span
                                                class="badge badge-light">{{item.SerialNum.length}}</span>
                                                </button>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                            </div>
                        </div>


                    </div>
                </div>
            </div>

        </div>
        <div style="height:100px;"></div>
        <div class="action-row">
            <div class="container">
                <div class=" row justify-content-center">
                   
                    <div id="btn2" class="col-4 col-md-4">
                        <button type="button" tapmode="" :disabled="receipt_btn" onclick="submitfrom();"
                            class="btn btn-primary btn-action btn-submit">{{lan['Confirm']}}</button>
                    </div>

                    <div id="btn3" class="col-4 col-md-4">
                        <button type="button" tapmode="" @click="print_label()"
                            :disabled="print_btn" class="btn btn-primary btn-action btn-print">{{lan['Print_Label']}}
                        </button>
                    </div>

                    <div v-show="list.length > 0" id="btn4" class="col-4 col-md-4">
                        <button type="button" tapmode="" onclick="close_win1();"
                            class="btn btn-primary btn-action btn-print">{{lan['Cancel']}}
                        </button>
                    </div>
                </div>

            </div>

        </div>
    </div>

</body>
<script type="text/javascript" src="../script/lang.js"></script>
<script type="text/javascript" src="../script/model.js"></script>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/vue.min.js"></script>
<script type="text/javascript" src="../script/jquery.min.js"></script>
<script type="text/javascript" src="../script/bootstrap.bundle.min.js"></script>
<script type="text/javascript" src="../script/bootstrap-select.min.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript">
    var postcount = 0;
    var returncount = 0;
    var postlist = [];
    var printsn = [];
    var tagspostcount = 0;
    var tags = [];
    const app = new Vue({
        el: '#app',
        data: {
            list: [],
            screenwidth: document.body.clientWidth,
            vendors: [],
            outinfo:"",
            inOutData:{},
            currentData:{},
            rowNum:1,
            requirenum: 0,
            scannum: 0,
            CustNum: 0,
            searchdata: {
                name: '',
                RMANum: '',//5425
                ArrivedDate: timenow(),
                custID: '',
            },
            uinfo: {},
            lotinfo: {},
            //postlist: [],
            //postlistids: [],
            create_btn: false,
            receipt_btn: true,
            confirm_btn:false,
            Lot_btn:false,
            snsCheck:false,
            print_btn: true,
            print_num: '',
        },
        mounted() {
            const that = this
            window.onresize = () => {
                return (() => {
                    that.screenwidth = document.body.clientWidth
                })()
            }
            this.showmodal();

            setTimeout(function () {
                $("#RMANum").focus();
            }, 500);

            //init_select();
        },
        methods: {
            list1_selectall(){
                for (let i = 0; i < this.list.length; i++) {
                    this.list[i].shoucai = 2;
                }
            },
            list2_selectall(){
                for (let i = 0; i < this.list.length; i++) {
                    this.list[i].shoucai = 1;
                }
            },
            print_label: function () {
                var btns = [];
                btns.push(lan['Print_Carton_Label']); //箱条码
                if(printsn.length > 0){
                    btns.push(lan['Print_SN_Label']);
                }
                var that = this;
                api.actionSheet({
                    title: lan['Tips'],
                    cancelTitle: lan['Cancel'],
                    buttons: btns
                }, function (ret, err) {
                    var index = ret.buttonIndex;
                    var key = index - 1;

                    if (btns[key] == lan['Print_Carton_Label']) {

                        print_type = 2;
                        that.print_carton();
                    }

                    if (btns[key] == lan['Print_SN_Label']) {
                        print_type = 1;
                        that.submit_sncode();
                    }
                });
            },
            async print_carton() {
                showProgress(lan['Loading']);
                print_tags = [];
                let ExpiryDate = ""
                console.log(JSON.stringify(this.list),33333)
                for (let key in this.list) {
                    console.log(JSON.stringify(key), 11111)
                    if (this.list[key].shoucai == 2) {
                        let item = this.list[key];
                        console.log(JSON.stringify(item), 222222)
                        item.LabelNum = item.PartNum + "/" +  item.LotNum;
                        print_tags.push(item);
                        
                    }
                }
                hideProgress();
                if (print_tags.length > 0) {
                    open_printpage2(print_tags, 1, 1, 2,0);
                } else {
                    api.toast({
                        msg: lan['No_Data_Submit'],
                        location: 'middle'
                    });
                }
            },
            submit_sncode() {
                print_tags = printsn;
                if (print_tags.length > 0) {
                    open_printpage(print_tags, 1, 3);
                } else {
                    api.toast({
                        msg: lan['No_Data_Submit'],
                        location: 'middle'
                    });
                }

            },
            checkDecimal(item, index) {
                // 获取输入的值
                let inputValue = item.OnhandQty;

                // 将输入值解析为浮点数
                let parsedValue = parseFloat(inputValue);

                // 如果解析成功，限制小数位数不超过 NumOfDec
                if (!isNaN(parsedValue)) {
                    const decimalCount = (inputValue.toString().split('.')[1] || "").length || 0;
                    if (decimalCount > item.NumOfDec) {
                    // 超过 NumOfDec 位小数，截取前 NumOfDec 位小数，不进行四舍五入
                    inputValue = inputValue.substring(0, inputValue.indexOf('.') + item.NumOfDec + 1);
                    }
                    item.OnhandQty = inputValue;
                    this.check_canclick()
                }
            },
            BatchProperties:function(item,index){
                let that = this
                let PartNum = item.PartNum || '';
                let LotNum = item.LotNum || '';
                if(!LotNum){
                    api.toast({
                        msg:lan['Please_Lot_nunber'],
                        location: 'middle'
                    });
                    return
                }
                if(PartNum != '' && LotNum != ''){
                    var data = {};
                    data.item = item;
                    data.PartNum = PartNum;
                    data.LotNum = LotNum;
                    data.index = index;
                    data.attribute_btn = item.attribute_btn
                    data.Lot_btn = app.Lot_btn;
                    data.title = lan['Batch_Properties'];
                    data.frame = "batch_properties";
                    
                    openNavWin2(data.frame, data);
                    app.$set(app.list[index],'BatchCheck',true)
                    if(!this.receipt_btn){
                        that.check_canclick()
                    }
                }
            },
            GenerateNewLotNum: function (index, shoucai) {

                var model = {
                    "vPartNum": this.list[index].PartNum
                }
                var that = this;

                api.ajax({
                    url: server + 'Erp.BO.LotSelectUpdateSvc/GenerateNewLotNum',
                    method: 'post',
                    returnAll: false,
                    headers: {
                        'Authorization': userinfo.Token,
                        'Content-Type': 'application/json;charset=utf-8'
                    },
                    data: {
                        body: JSON.stringify(model)
                    }
                }, function (ret, err) {
                    ajaxing = 0;
                    console_debug(ret, err);
                    console.log(JSON.stringify(model),22222)
                    console.log(JSON.stringify(ret),111111)
                    hideProgress();
                    if (ret) {
                        that.$set(that.$data.list[index], 'LotNum', ret.parameters.vNewLotNum);
                        // that.LotSelectUpdate(index);
                    } else {
                        api.toast({
                            msg: lan['TrackLots_Error'],
                            location: 'middle'
                        });
                    }
                    that.check_canclick();

                });


                },
            onWareQuery(item,index){
                item.warehouseFlag = true;
            },
            onWareScan(item,index){
                item.warehouseFlag = false;
            },
            onBinQuery(item,index){
                item.binFlag = true;
            },
            onBinScan(item,index){
                item.binFlag = false;
            },
            onLotQuery(item,index){
                item.lotFlag = true;
            },
            onLotScan(item,index){
                item.lotFlag = false;
            },
            addPartChange(item,k){
                loadWarehouseCodeData(item,k);
            },
            searData(){
                if(app.searchdata.RMANum){
                    userinfo = get_user_info();
                    let filter = "?CompID=" + userinfo.Company + "&Site=" + userinfo.Site

                    if(this.searchdata.RMANum){
                        filter += '&RMANum='+ this.searchdata.RMANum
                    }
                    let that = this
                    that.searchdata.custID = ""
                    console.log(filter,4444)
                    //console_debug(filter, '');
                    showProgress(lan['Loading']);
                    api.ajax({
                        url: server + 'BaqSvc/WMS_RMAList/'+filter,
                        method: 'get',
                        returnAll: false,
                        headers: {
                            'Authorization': userinfo.Token,
                        },
                        data: {},
                    }, function (ret, err) {
                        ajaxing = 0;
                        console.log(JSON.stringify(ret.value),99999)
                        hideProgress();
                        if (ret && ret.value.length > 0) {
                            that.searchdata.custID = ret.value[0].Customer_CustID
                            console.log(that.searchdata.custID)
                        } else {
                            api.toast({
                                msg: "no data!",
                                location: 'middle'
                            });
                        }

                    });
            
                }
               },
      
            binNumChange:function(item,index){
                   
                setTimeout(function(){
                    loadBinData(item,index)
                },100)
                   
            },
            numChange:function(item,index){
                setTimeout(function(){
                    loadPartNumStatus(item,index)
                },100)
            },
            lotFocus:function(item,index){
                
                setTimeout(function(){
                    scan3(item,index)
                },100)
            },
            lotBlur:function(item,index){
               
                loadPartNumStatus(item,index)
            },
            warehouseFocus:function(item,index){
                setTimeout(function(){
                    scan1(item,index)
                },100)
            },
            binFocus:function(item,index){
                if(item.WarehouseCode == ""){
                    api.toast({
                        msg: lan['WareHouseCode_placeholder'],
                        location: 'middle'
                    });
                    return;
                }
                setTimeout(function(){
                    scan2(item,index)
                },100)
            },
            check_canclick: function () {
                var canclick = false;
                var tc = false;
                var sr = false;
                var tg = false;
                var sc = true;
                for (i in this.list) {
                    if (this.list[i].shoucai == 2) {
                        let item =this.list[i]
                            if(item.OnhandQty == ""){
                                tg = true;
                            }
                            if (this.list[i].is_SerialNum == 1) {
                                console.log(this.receipt_btn,22222)
                                if (item.SerialNum.length == 0) {
                                    sr = true;
                                }
                            }
                            if (this.list[i].is_Lot == 1) {
                                if (!item.LotNum || item.LotNum == '') {
                                    tc = true;
                                }
                            }

                        sc = false;
                    }

                }
            
                if (tc  || tg  || sc || sr) {
                    canclick = true;
                }

                this.receipt_btn = canclick;
                console.log(this.receipt_btn,11111)
            },
            toshou: function (item,index) {
                var i = index;
                console.log(JSON.stringify(userinfo),222222)
                console.log(JSON.stringify(item),111111)
                var shoucai = this.list[i].shoucai == 1 ? 2 : 1;
               
                console_debug(i, shoucai);
                var that = this;
                var unk = 0;
           
                if (that.list[i].is_Lot != -1) {
                    setTimeout(function () {
                        that.$set(that.$data.list[i], 'shoucai', shoucai);
                        LotAttributeOption(index,item)
                        if(shoucai == 2){
                            loadWarehouseCodeData(item,index)
                        }
                    }, 500)
                    if(item.shoucai == 1){
                        that.$set(that.$data.list[i], 'list', []);
                        item.itemChecked = false;
                    }
                    return;
                }
               

            },
          
            toSerial: function (item, index) {
                if(!item.OnhandQty){
                    api.toast({
                        msg: lan['palase_enter'] + lan['Qty'],
                        location: 'middle'
                    });
                    return
                }
                var data = {};
                item.SerialNum = []
                var InputOurQty = processNumber(item.OnhandQty, item.NumOfDec);
                for (let i = 0; i < InputOurQty; i++) {
                    item.SerialNum.push({
                        'type': i+1,
                        'SerialNumber': '',
                    })
                }
                data.post = item;
                data.post.Lot_btn = app.Lot_btn;
                data.post.snsCheck = app.snsCheck
                data.post.index = index;
                data.searchdata = this.searchdata;
                data.title = lan['RMA_Receipts'];
                data.frame = "sn_receipts";
                data.right = [{
                    text: lan["Scan"],
                    color: '#fff',
                }];
                console_debug(data,"sn_receipts");

                openNavWin2(data.frame, data);

            },
            checkNum: function (item, index) {
                var OnhandQty = processNumber(this.list[index].OnhandQty,this.list[index].NumOfDec);
                if (OnhandQty <= 0) {
                    OnhandQty = 1;

                }
                this.$set(this.$data.list[index], 'OnhandQty', OnhandQty);
            },
            showmodal: function () {
                if (this.screenwidth < 576) {
                    $('#exampleModal').modal('show');
                    //init_select();
                } else {

                    $('#JobNum').focus();
                }
            },
            hidemodal: function () {
                $('#exampleModal').modal('hide');
            },
        }
    });
    apiready = function () {
        api.parseTapmode();
        server = getapi();
        back_listen();
        app.vendors = get_prefs_data("Vendors");
        app.uinfo = get_user_info();
        userinfo = get_user_info();
        app.searchdata.name = userinfo.Name;
        api.addEventListener({
            name: 'infrared_scanning'
        }, function (ret, err) {
            console.log(JSON.stringify(ret));
            $("input:focus").val(ret.value.str);
            app.searchdata.RMANum =  $("#RMANum").val();
            
            if (ret && ret.value && ret.value.str && is_scan == 0) {
                app.searchdata.RMANum = ret.value.str;
                app.searData()
            }

        });
        api.addEventListener({
            name: 'keyback',
            extra: {
                slidBackIntercept: true    
            }
        }, function (ret, err) {
            close_win1() 

        });

        api.addEventListener({
            name: 'batch_properties_update'
        }, function (ret, err) {
            if (ret && ret.value) {
                var snposts1 = ret.value;
                console.log(JSON.stringify(snposts1), 55555)
                app.Lot_btn = snposts1.Lot_btn
                app.$set(app.$data.list[snposts1.index],'attribute_btn',snposts1.attribute_btn)
                api.closeWin({ name: 'batch_properties' });
                console.log(JSON.stringify(app.list),66666)
            }
        });

        api.addEventListener({
            name: 'sn_receipts'
        }, function (ret, err) {
            if(ret && ret.value){
                var snposts = ret.value;
                console.log(JSON.stringify(snposts),33333)
                app.list[snposts.index].OnhandQty = snposts.OnhandQty;
                app.list[snposts.index].OldQty = snposts.OldQty;
                app.list[snposts.index].SerialNum = snposts.SerialNum;
                app.check_canclick()
                console.log(JSON.stringify(app.list),44444)
                api.closeWin({name: 'sn_receipts'});
            }
        });
        api.addEventListener({ name: 'navitembtn' }, function (ret, err) {
            if(ret.type == 'left'){
                close_win1() 
               
            }
            if (ret.type == 'right') { 
                scan()
            }
        });

    }
     //关闭取消事件
     function close_win1() {
        var msg = app.receipt_btn && app.list.length != 0 ? lan['deliver__cancel_tips'] : lan['deliver__cancel_tips'];
        if(app.receipt_btn && app.list.length != 0){
            api.confirm({
                title: lan['Tips'],
                msg: msg,
                buttons: [lan['NO'], lan['YES'], lan['Cancel']]
            }, function (ret, err) {
                var index = ret.buttonIndex;
                if (index == 2) {
                    submitfrom();
                } else if (index == 1) {
                    close_win();
                }
            });
        }else{
            close_win();
        }

    }
    function scan1(item,index){
        var FNScanner = api.require('FNScanner');
        FNScanner.open({
            autorotation: true
        }, function (ret, err) {
            console_debug(ret, err);
            if (ret) {
                if (ret.eventType == 'success') {
                    app.$set(app.$data.list[index],'WareHouseCode',ret.content)
                    setTimeout(function(){
                        loadBinData(item,index)
                    },300)
                }
            } 
        });
          
    }
    function scan2(item,index){
        var FNScanner = api.require('FNScanner');
        FNScanner.open({
            autorotation: true
        }, function (ret, err) {
            console_debug(ret, err);
            if (ret) {
                if (ret.eventType == 'success') {
                    app.$set(app.$data.list[index],'BinNum',ret.content)
                    setTimeout(function(){
                        loadPartNumStatus(item,index)
                    },300)
                }
            } 
        });
          
    }
    function scan3(item,index){
        var FNScanner = api.require('FNScanner');
        FNScanner.open({
            autorotation: true
        }, function (ret, err) {
            console_debug(ret, err);
            if (ret) {
                if (ret.eventType == 'success') {
                    app.$set(app.$data.list[index],'LotNum',ret.content)
                    setTimeout(function(){
                        loadPartNumStatus(item,index)
                    },300)
                }
            } 
        });
          
    }

    function scan() {

        var FNScanner = api.require('FNScanner');
        FNScanner.open({
            autorotation: true
        }, function (ret, err) {
            console_debug(ret, err);
            if (ret) {
                if (ret.eventType == 'success') {
                    app.outinfo = ret.content
                    if(!app.confirm_btn){
                        app.searchdata.RMANum = ret.content;
                        app.searData()
                    }
                    
                }

            } else {
                //alert(JSON.stringify(err));
            }
        });
    }
    function LotAttributeOption(index,item){
        api.ajax({
            url: server + 'BaqSvc/WMS_LotAttributeOption/?CompID=' + userinfo.Company + '&PartNum=' + item.PartNum + '',
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
                'Content-Type': 'application/json;charset=utf-8'
            },
            data: {}
        }, function (ret, err) {
            ajaxing = 0;
            if (ret && ret.value.length>0) {
                console.log(JSON.stringify(ret.value[0]), 666666)
                var keys = Object.keys(ret.value[0]);
                var allN = keys.filter(function(key) {
                    return key !== "Part_Company" && key !== "RowIdent";
                    }).every(function(key) {
                    return ret.value[0][key] === "N";
                });
                console.log(allN,777777)
                if (allN) {
                   app.$set(app.$data.list[index],'BatchProperties',true)
                } else {
                    app.$set(app.$data.list[index],'BatchProperties',false)
                }

            } 

        });
    }
    async function loadWarehouseCodeData(data,k) {
        userinfo = get_user_info();
        if (!userinfo.Token) {
            return;
        }
        await api.ajax({
            url: server + 'BaqSvc/WMS_WarehouseForPart/?CompID=' + userinfo.Company + "&Site=" + userinfo.Site +"&PartNum="+data.PartNum,
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
            },
            data: {}
        }, function (ret, err) {
            console.log(JSON.stringify(ret), 22222)
            if (ret && ret.value.length > 0) {
                app.$set(app.$data.list[k],'WareHouseCodeList',ret.value)
            }
        });
    }
    async function loadBinData(item,index) {
        userinfo = get_user_info();
        $('.myselect4').selectpicker('destroy'); // 先销毁
        await api.ajax({
            url: server + 'BaqSvc/WMS_WhseBin/?CompID=' + userinfo.Company + "&WarehouseCode=" + item.WareHouseCode,
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
            },
            data: {

            }
        }, function (ret, err) {
            if (ret && ret.value.length > 0) {
               app.$set(app.$data.list[index],'BinNumList',ret.value)
                setTimeout(function () {
                    app.check_canclick()
                }, 200)
            }

        });
    }
    function loadPartNumStatus(item,index){
        userinfo = get_user_info();
        let filter = "?CompID=" + userinfo.Company;
        if (item.PartNum) {
            filter += "&PartNum=" + item.PartNum;
        }
        if(item.WareHouseCode){
            filter += "&WhseCode=" + item.WareHouseCode;
        }
        if(item.BinNum){
            filter += "&Bin=" + item.BinNum;
        }
        if(item.LotNum){
            filter += "&LotNum=" + item.LotNum;
        }
        api.ajax({
            url: server + 'BaqSvc/WMS_PartBinOnhand/' + filter,
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
            },
            data: {} 
        },function(ret,err){
            console.log(filter,44444)
            console.log(JSON.stringify(ret),111111)
            console.log(JSON.stringify(err),222222)
            if(ret && ret.value.length>0){
                app.check_canclick()
                if(item.Part_TrackLots && item.LotNum != ""){
                    app.$set(app.$data.list[index],'MaxQty',processNumber(ret.value[0].PartBin_OnhandQty,item.NumOfDec)) 
                }
                if(!item.Part_TrackLots){
                    app.$set(app.$data.list[index],'MaxQty',processNumber(ret.value[0].PartBin_OnhandQty,item.NumOfDec))   
                }    
            }
        })
    }
   
    
    function loadData() {
        userinfo = get_user_info();
        app.list = [];
        let filter = "?CompID=" + userinfo.Company + "&Site=" + userinfo.Site

        if(app.searchdata.RMANum){
            filter += '&RMANum='+ app.searchdata.RMANum
        }
        if(app.searchdata.custID){
            filter += '&CustID='+app.searchdata.custID
        }
        console.log(filter,4444)
        //console_debug(filter, '');
        showProgress(lan['Loading']);
        api.ajax({
            url: server + 'BaqSvc/WMS_RMAList/'+filter,
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
            },
            data: {},
        }, function (ret, err) {
            ajaxing = 0;
            console.log(JSON.stringify(ret.value),99999)
            hideProgress();
            if (ret && ret.value.length > 0) {
                var newlist = init_list(ret.value);
                if (newlist.length == 0) {
                    api.toast({
                        msg: "no data!",
                        location: 'middle'
                    });
                    return;
                }

                // PartNumTrackSerialNum
                app.requirenum = 0;
                app.list = app.list.concat(newlist);
                console.log(JSON.stringify(app.list),44444)
                app.confirm_btn = true
                $('#exampleModal').modal('hide');

            } else {
                api.toast({
                    msg: "no data!",
                    location: 'middle'
                });
            }

        });
    }
    //JobMtl
    function init_list(data) {
        var ret = [];
        for (i in data) {
            data[i].PartNum = data[i].RMADtl_PartNum;
            data[i].PartDescription = data[i].RMADtl_LineDesc;
            data[i].NumOfDec = data[i].UOM_NumOfDec;
            data[i].IUM = data[i].RMADtl_ReturnQtyUOM;
            data[i].CustID = data[i].Customer_CustID;
            data[i].RMANum = data[i].RMADtl_RMANum;
            data[i].RMALine = data[i].RMADtl_RMALine;
            data[i].OrderNum = data[i].RMADtl_OrderNum;
            data[i].OrderLine = data[i].RMADtl_OrderLine;
            data[i].OrderRelNum = data[i].RMADtl_OrderRelNum;
            data[i].WareHouseCodeList = [];
            data[i].BinNumList = [];
            data[i].WareHouseCode = "";
            data[i].BinNum = ""
            data[i].shoucai = 1;
            data[i].itemChecked = false;
            data[i].OnhandQty = "";
            data[i].OldQty="";
            data[i].is_Lot = -1; //批号判断 -1 未查询  1 需创建 2 不需创建
            data[i].is_SerialNum = -1; //序列号判断 -1 未查询  1 需创建 2 不需创建
            if (data[i].Part_TrackLots) {
                data[i].is_Lot = 1
            } else {
                data[i].is_Lot = 2
            }
            if (data[i].Part_TrackSerialNum) {
                data[i].is_SerialNum = 1; 
            } else {
                data[i].is_SerialNum = 2; 
            }
            data[i].BatchProperties = true;
            data[i].attribute_btn = false;
            data[i].lotFlag = false;
            data[i].warehouseFlag = false;
            data[i].binFlag = false;
            data[i].SerialNum = [];
            data[i].TotalQty = processNumber(data[i].RMADtl_ReturnQty,data[i].UOM_NumOfDec);
            ret.push(data[i]);

        }
        return ret;
    }
   
    function submitfrom() {
        console.log(JSON.stringify(app.list),999999)
        // return
        var postlist = [];
        for (i in app.list) {
            var item = app.list[i];
            if(item.shoucai == 2){

                if(!app.list[i].attribute_btn && !app.list[i].BatchProperties){
                    api.toast({
                        msg: lan['Lot_Attribute_placeholder'],
                        location: 'middle'
                    });
                    hideProgress();
                    return false; 
                }
                var row = {
                    "RMANum": app.searchdata.RMANum,     //-- 出货人 （使用用户名 登陆界面选择的内容）
                    "RMALine": item.RMALine,			//	-- 客户编号
                    "Quantity": item.OnhandQty,			//	--出货数量
                    "ReceiptDate": app.searchdata.ArrivedDate,//	--出货日期
                    "IUM": item.IUM,				//--单位
                    "WareHouseCode": item.WareHouseCode,	//--出货仓库
                    "BinNum": item.BinNum,	//	--出货仓位
                    "LotNum": item.LotNum,				//--批号
                }



                var arr = [];
                if(item.SerialNum){
                    if(item.SerialNum.length>0){
                        var SerialNum = item.SerialNum;
                        for(k in SerialNum){
                            var row1 = {};
                            row1.SerialNumber = SerialNum[k].SerialNumber;
                            arr.push(row1); 
                            var sn = get_new_arr(item.SerialNum);
                            sn.LabelNum =item.PartNum + "/" +item.LotNum ;
                            sn.WareHouseCode = item.WarehouseCode;
                            sn.BinNum = item.BinNum;
                            sn.LotNum = item.LotNum;
                            sn.SNStatus = 'INVENTORY';
                            sn.JobNum = item.JobNum;
                            sn.AssemblySeq = 0;
                            sn.MtlSeq = 0;
                            printsn.push(sn);
                        }
                    }
                }
                if(arr.length>0){
                    row.SelectedSerialNumbers = arr;
                }
                postlist.push(row);
                
            }

        }
        if (!postlist) {
            api.toast({
                msg: lan['No_Data_Submit'],
                location: 'middle'
            });
            return;
        }
        console.log(JSON.stringify(postlist),222222)
        var datalist = {};
        for (i in postlist) {
            var item = get_new_arr(postlist[i]);
            var key = item.PartNum + item.RMANum + item.RMALine + item.WareHouseCode + item.BinNum + item.LotNum;
            if (datalist[key]) {
                datalist[key].Quantity = datalist[key].Quantity + item.Quantity;
                if (datalist[key].SelectedSerialNumbers) {
                    datalist[key].SelectedSerialNumbers = datalist[key].SelectedSerialNumbers.concat(item.SelectedSerialNumbers);
                } else {
                    datalist[key].SelectedSerialNumbers = item.SelectedSerialNumbers;
                }
            } else {
                datalist[key] = item;
            }
        }
        var postrows = [];
        for (key in datalist) {
            postrows.push(datalist[key]);
        }
        var data1 = {
            "CompanyID": userinfo.Company,
            "PlantID": userinfo.Site,
            "UserName": userinfo.Name,
            "Password": userinfo.password,
            "Data": JSON.stringify(postrows)
        }

        console_debug(data1,"提交数据");
        // return;


        if(ajaxing){return;}showProgress(lan['Loading']);


        submit_custship(data1);
       
    }

    function submit_custship(item) {

        api.ajax({
            url: wmsserver + 'rmarcv/',
            method: 'post',
            returnAll: false,
            headers: {
                'token': wmstoken,
                'Content-Type': 'application/json;charset=utf-8'
            },
            //dataType: 'text',
            data: {
                body: create_submit_data(item)
            }
            //data: {values: data1}
        }, function (ret, err) {
            ajaxing = 0;
            console_debug(ret, err);
            // console.log(err,444444)
            if (ret && ret.code == 1) {
                api.alert({
                    title: lan['Tips'],
                    msg: lan['Submitted_successfully']
                }, function (ret, err) {
                    app.receipt_btn = true
                    app.confirm_btn = false
                    app.print_btn = false
                    app.Lot_btn = true
                    hideProgress();
                });
            } else {
                // console.log(JSON.stringify(ret),55555)
                app.receipt_btn = true
                hideProgress();
                errMassage(ret.msg)
            }

        });
    }
  
</script>

</html>